package com.chenfan.mcn.job;

import com.chenfan.mcn.service.MonthlyTargetService;
import com.chenfan.mcn.utils.DateUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 月度目标-各金额/目标达成率计算-定时任务
 *
 * @author wulg
 * @date 2022-04-06
 **/
@Component
public class MonthlySalesJob {

    @Autowired
    private MonthlyTargetService monthlyTargetService;

    @SneakyThrows
    @XxlJob(value = "monthly_target_statistics")
    public ReturnT<String> monthlyTargetStatisticsJob(String param) {
        Date date = null;
        if (StringUtils.isNotBlank(param)) {
            date = DateUtils.parseDate(param, "yyyyMM");
        } else {
            date = DateUtil.getPreMonthDate(new Date());
        }
        monthlyTargetService.updateMonthlySales(date);
        return ReturnT.SUCCESS;
    }
}
